package com.huawei.rbac.web.controller;

import com.huawei.rbac.domain.Department;
import com.huawei.rbac.query.QueryObject;
import com.huawei.rbac.service.IDepartmentService;
import com.huawei.rbac.util.RequiredRermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService service;

    @RequestMapping("/list")
    @RequiredRermission({"部门列表","department:list"})
    public String list(Model model,QueryObject qo){
        model.addAttribute("result",service.query(qo));
        return "department/list";
    }

    @RequestMapping("/delete")
    @RequiredRermission({"部门删除","department:delete"})
    public String delete(Long id){
        if(id != null){
             service.delete(id);
        }
        return "redirect:/department/list";
    }

    @RequestMapping("/saveOrUpdate")
    @RequiredRermission({"部门保存或更新","department:saveOrUpdate"})
    public String saveOrUpdate(Department d){
        service.saveOrUpdate(d);
        return "redirect:/department/list";
    }

    @RequestMapping("/input")
    @RequiredRermission({"部门编辑","department:input"})
    public String input(Model model,Long id){
        if(id != null){
            Department d = service.get(id);
            model.addAttribute("d",d);
        }
        return "department/input";
    }
}
